class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i < tokens.length;i++) {
            String str = tokens[i];
            if(str.equals("+")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(x+y);
            } else if(str.equals("-")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(y-x);
            } else if(str.equals("*")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(x*y);
            } else if(str.equals("/")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(y/x);
            } else {
                int a = Integer.parseInt(str);
                stack.push(a);
            }
        }
        return stack.pop();
    }
}